package com.xueyi.system.auxiliary.service.impl;

import com.xueyi.system.auxiliary.domain.query.AuxiliaryQuery;
import com.xueyi.system.auxiliary.domain.dto.AuxiliaryDto;
import com.xueyi.system.auxiliary.service.IAuxiliaryService;
import com.xueyi.system.auxiliary.manager.IAuxiliaryManager;
import com.xueyi.system.material.domain.query.MaterialQuery;
import com.xueyi.system.material.domain.dto.MaterialDto;
import com.xueyi.system.material.service.IMaterialService;
import cn.hutool.core.util.ObjectUtil;

import java.io.Serializable;
import java.util.Collection;
import com.xueyi.common.web.entity.service.impl.SubBaseServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 投入品信息管理 服务层处理
 *
 * @author yanhe
 */
@Service
public class AuxiliaryServiceImpl extends SubBaseServiceImpl<AuxiliaryQuery, AuxiliaryDto, IAuxiliaryManager, MaterialQuery, MaterialDto, IMaterialService> implements IAuxiliaryService {

    /**
     * 查询投入品信息对象列表 | 数据权限 | 附加数据
     *
     * @param auxiliary 投入品信息对象
     * @return 投入品信息对象集合
     */
    @Override
    //@DataScope(userAlias = "createBy", mapperScope = {"AuxiliaryMapper"})
    public List<AuxiliaryDto> selectListScope(AuxiliaryQuery auxiliary) {
        return baseManager.selectListExtra(auxiliary);
    }


    /**
     * 设置子数据的外键值
     */
    @Override
    protected void setForeignKey(Collection<MaterialDto> materialList, MaterialDto material, AuxiliaryDto auxiliary, Serializable key) {
    Long id =
        ObjectUtil.isNotNull(auxiliary) ? auxiliary.getMaterialId() :(Long)
        key;
        if (ObjectUtil.isNotNull(material))
    material.setId(id);
        else
    materialList.forEach(sub -> sub.setId(id));
    }
}